﻿@{
    Layout = "~/Shared/Layouts/_AdminLayout.cshtml";
    Page.Title = "Нарачки";
    
    var showShippedOrders = false;
    
    if(IsPost)
    {
        showShippedOrders = Request["showShippedOrders"].AsBool();
    }

    var db = Database.Open("VirtualeShop");
    var sqlCommand = "SELECT Orders.OrderId, Orders.OrderShipped, Orders.OrderTotal, " + 
                     "Orders.OrderDateTime, UserProfile.Email FROM Orders " + 
                     "INNER JOIN UserProfile ON Orders.UserId = UserProfile.UserId " +
                     "WHERE OrderShipped = @0 " + 
                     "ORDER BY OrderDateTime DESC";

    var result = db.Query(sqlCommand, showShippedOrders);
                    
    var ordersGrid = new WebGrid(source: result,
                                 rowsPerPage: 20);

}

<h1>Преглед на нарачки</h1>
<form action="Default" method="post">
    <p>
        Неиспорачани нарачки @Html.RadioButton("showShippedOrders", "false", !showShippedOrders)
        Испорачани нарачки @Html.RadioButton("showShippedOrders", "true", showShippedOrders)
        <input type="submit" value="Почни"/>
    </p>
</form>
<div class="grid">
    @ordersGrid.GetHtml(
        tableStyle: "grid",
        headerStyle: "gridHeader",
        alternatingRowStyle: "gridAlt",
        footerStyle: "gridFooter",
        columns: ordersGrid.Columns(
            ordersGrid.Column("OrderId",
                              "Број на нарачка"),
            ordersGrid.Column("Email",
                              "Корисник",
                              format: @<text>
                                          <a href="mailto:@item.Email">
                                              @item.Email
                                          </a>
                                      </text>),
            ordersGrid.Column("OrderShipped",
                              "Испорачано?"),
            ordersGrid.Column("OrderTotal",
                              "Вкупна вредност",
                              format: @<text>
                                          £@item.OrderTotal
                                      </text>),
            ordersGrid.Column("OrderDateTime",
                              "Испорачано"),
            ordersGrid.Column(null,
                              null,
                              format: @<text>
                                          <a href="OrderDetails/@item.OrderId">
                                              Повеќе...
                                          </a>
                                      </text>)
        )
    )
</div>